#include "iostream"
using namespace std;
int main(){
    long a1 ;
    cin>>a1;
    long* is = new long[a1];
    for (long i = 0; i < a1; i++) {
        cin>>is[i];
    }
    long a2 ;
    cin>>a2;
    long* maxs = new long[a2];
    for (int i = 0; i < a2; i++) {
        long str ,end , max=0;
        cin>>str>>end;
        for (long j = str; j <= end; j++) {
            if (max<is[j]){
                max = is[j];
            }
        }
        maxs[i] = max;
    }
    for (int i = 0; i < a2; i++) {
        cout<<maxs[i]<<endl;
    }
}